var express = require('express');
var app = express();
var router = require('./app/router/index.js');
var db = require('./app/models/db.js');
var bodyParser = require('body-parser');
// 创建 application/x-www-form-urlencoded 编码解析
var urlencodedParser = bodyParser.urlencoded({ extended: false })
 
//跨域
app.all('*', function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
    res.header("X-Powered-By",' 3.2.1')
    res.header("Content-Type", "application/json;charset=utf-8");
    next();
});
//当前端GET方式访问http://localhost:3000//health/fetchdorm接口时，则采用router文件夹下面index.js文件中的fetchDorm逻辑

app.get('/health/fetchdorm', router.fetchDorm);

app.post('/login',urlencodedParser, router.login);
app.post('/addProject',urlencodedParser, router.addProject);
app.post('/userDepament',urlencodedParser, router.userDepament);
app.post('/appProject',urlencodedParser, router.appProject);
app.post('/infoProject',urlencodedParser, router.infoProject);
app.post('/updataStateProject',urlencodedParser, router.updataStateProject);
app.post('/updataProject',urlencodedParser, router.updataProject);
app.post('/updataProcessProject',urlencodedParser, router.updataProcessProject);
app.post('/addUser',urlencodedParser, router.addUser);
app.post('/addDynamic',urlencodedParser, router.addDynamic);

app.get('/userList', router.fetchUserList);
app.get('/projectList', router.projectList);
app.get('/dynamicList', router.dynamicList);

app.listen(3000, () => {
    console.log('node服务器监听3000端口成功');
})